//
// Created by xdc on 2025/11/10.
//
#include "show_user.h"
int show_user_information(){
    const char * show_sql="select * from front_user";
    sqlite3_stmt * show_stmt;
    int rc= sqlite3_prepare_v2(db,show_sql,-1,&show_stmt,NULL);
    if (rc!=SQLITE_OK){
        fprintf(stderr,"预编译展示失败%s\n", sqlite3_errmsg(db));
        sqlite3_finalize(show_stmt);
        return -1;
    }
    rc= sqlite3_step(show_stmt);
    int row_count=0;
    printf("\n======= 用户信息列表 =======\n");
    printf(
            "+----+----------------+----------------+--------+----------------+------------+----------+-------+\n"
            "| 用户ID | 用户姓名  | 用户密码         | 用户手机号      | 用户当前状态(0:未拉黑,1:拉黑）|   \n"
            "+----+----------------+----------------+--------+----------------+------------+----------+-------+\n"
    );
    while (rc==SQLITE_ROW){
        row_count++;
        int id= sqlite3_column_int(show_stmt,0);
        const char * user_name= (const char *)sqlite3_column_text(show_stmt,1);
        const char * user_password= (const char *)sqlite3_column_text(show_stmt,2);
        const char * user_phone= sqlite3_column_text(show_stmt,3);
        int user_status= sqlite3_column_int(show_stmt,4);
        printf(
                "| %-6d | %-7s | %-14s | %-14s | %-15d |\n",
                id,
                user_name ? user_name : "未知",
                user_password ? user_password : "未知",
                user_phone ? user_phone : "未知",
                user_status

        );
        rc = sqlite3_step(show_stmt);
    }printf(
            "+----+----------------+----------------+--------+----------------+------------+----------+-------+\n"
    );

    if (rc!=SQLITE_DONE){
        fprintf(stderr,"查询结果遍历失败：%s\n", sqlite3_errmsg(db));
        sqlite3_finalize(show_stmt);
        return -1;
    }
    sqlite3_finalize(show_stmt);
    if (row_count == 0) {
        printf("当前没有任何用户信息\n");
    } else {
        printf("共展示 %d 条用户信息\n", row_count);
    }
    return 0;
}